var fileUrl = '';
    var mailReg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    // 上传文件以获取地址
    $("#upfile-0").on("change", function () {
      var fileData = $("#upfile-0")[0].files[0];//最终文件对象
      var accept =
        /.+(.JPEG|.jpeg|.JPG|.jpg|.GIF|.gif|.BMP|.bmp|.PNG|.png|.avi|.MOV|.mov|.mp4|.pdf|.xls|.doc|.docx|.xlsx|.txt)$/;//扩展名
      if (fileData) {
        if (fileData.size > 10 * 1024 * 1024) {//10M
          alert("文件太大,请重新选择");
        } else {
          if (!accept.test(fileData.name)) {
            alert("不支持的文件")
            return
          };

          $(".form-control-file").val(fileData.name)
          var form = new FormData();
          form.append("file", fileData);
          $.ajax({
            type: "POST",
            url: `${HOST}/index/contact/upload`,
            processData: false,
            contentType: false,
            data: form,
            dataType: "json",
            success: function (data) {
              if(data.code==2){
                fileUrl = data.src
              }
            },
            error: function (e) {
              console.log(e)
            }
          })
        }
      }

    })

    function submitData() {
      var mailReg = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
      var theme = $(".theme-txt").val().trim()
      var name = $(".theme-get-name").val().trim()
      var email = $(".theme-get-email").val().trim()
      var data = fileUrl || ""
      var message = $(".contact-textarea-input").val().trim()

      if(!theme){
        alert("请输入主题");return
      }
      if(!name){
        alert("请输入姓名或昵称");return
      }
      if(!email){
        alert("请输入电子邮件地址");
        return;
      }else{
        if(mailReg.test(email)==false){
          alert("电子邮件格式不正确")
          return
        }
      }
      if(!message){
        alert("请输入内容");return
      }

      // console.log(data)
      $.ajax({
        url: `${HOST}/index/contact/contact`,
        type: "POST",
        data: { name,theme,data,email,message},
        success: function (res) {
          if(res.success==1){
            alert(res.data.info)
            location.href="./contact-us.html"
          }
        },
        error: function (e) {
          console.log(e)
        }
      })

    }

    $(".contact-send").click(function () {
      submitData()
    })